package com.mall.search.service.config;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.core.convert.SolrJConverter;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;

/**
 * @author Administrator
 * 要手动开启solrRepository，配置要扫描repository的包
 */
@Configuration
@EnableSolrRepositories(
        basePackages = "com.mall.search.service.repository"
)
public class SolrConfiguration {

    @Value("${spring.data.solr.core}")
    private String solrCore;

    @Value("${spring.data.solr.host}")
    private String solrHost;


    /**
     * 注入solrTemplate，springboot默认是不会自动提供的
     * @param solrClient
     * @return
     */
    @Bean()
    public SolrTemplate solrTemplate(SolrClient solrClient){
        SolrTemplate template = new SolrTemplate(solrClient);
        template.setSolrCore(solrCore);
        template.setSolrConverter(new SolrJConverter());
        template.afterPropertiesSet();
        return template;
    }

}
